﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CApAPPWaypoint
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System.ComponentModel;


namespace DnProcessSimulateCommands;

public class CApAPPWaypoint : INotifyPropertyChanged
{
  private CApAPPTask m_task;
  private int m_waypointRank;
  private KiAppWaypointEx m_kiWaypoint;

  public CApAPPWaypoint(CApAPPWaypoint i_other)
  {
    this.m_kiWaypoint = new KiAppWaypointEx(i_other.KiWaypoint);
  }

  public CApAPPWaypoint(KiAppWaypointEx i_kiWp) => this.m_kiWaypoint = i_kiWp;

  public CApAPPTask Task
  {
    get => this.m_task;
    set => this.m_task = value;
  }

  public int WaypointRank
  {
    get => this.m_waypointRank;
    set => this.m_waypointRank = value;
  }

  public KiAppWaypointEx KiWaypoint => this.m_kiWaypoint;

  public string Name => this.KiWaypoint.Name;

  public string ZoneLabel
  {
    get => this.KiWaypoint.ZoneLabel;
    set => this.KiWaypoint.ZoneLabel = value;
  }

  public CApAPPMotionType TargetType
  {
    get => (CApAPPMotionType) this.KiWaypoint.TargetType;
    set => this.KiWaypoint.TargetType = (KiAppMotionType) value;
  }

  public CApAPPWaypointStatus WaypointStatus
  {
    get => (CApAPPWaypointStatus) this.KiWaypoint.WaypointStatus;
    set => this.KiWaypoint.WaypointStatus = (KiAppWaypointStatus) value;
  }

  public void StatusDidChanged() => this.NotifyPropertyChanged("WaypointStatus");

  public string ClashName => CApAPPWaypoint.ConvertWpStatusToString(this.WaypointStatus);

  public int ZoneRank => this.KiWaypoint.ZoneRank;

  public void ZoneNameDidChanged() => this.NotifyPropertyChanged("ZoneName");

  public CApAPPMotionTypeName MotionTypeName
  {
    get
    {
      CApAPPMotionTypeName motionTypeName = CApAPPMotionTypeName.Joint;
      switch (this.MotionType)
      {
        case CApAPPMotionType.LinearMotion:
          motionTypeName = CApAPPMotionTypeName.Linear;
          break;
        case CApAPPMotionType.JointMotion:
          motionTypeName = CApAPPMotionTypeName.Joint;
          break;
      }
      return motionTypeName;
    }
    set
    {
      if (value != CApAPPMotionTypeName.Joint)
      {
        if (value != CApAPPMotionTypeName.Linear)
          return;
        this.MotionType = CApAPPMotionType.LinearMotion;
      }
      else
        this.MotionType = CApAPPMotionType.JointMotion;
    }
  }

  public CApAPPWaypointPlanSuccess WaypointPlanSuccess
  {
    get => (CApAPPWaypointPlanSuccess) this.KiWaypoint.WaypointPlanSuccess;
    set => this.KiWaypoint.WaypointPlanSuccess = (KiAppWaypointPlanSuccess) value;
  }

  public void WaypointPlanSuccessDidChanged() => this.NotifyPropertyChanged("WaypointPlanSuccess");

  public virtual KiAppLocationEx SimulatedApproachLocation
  {
    get => this.KiWaypoint.SimulatedApproachLocation;
    set => this.KiWaypoint.SimulatedApproachLocation = value;
  }

  public virtual KiAppLocationEx SimulatedDepartLocation
  {
    get => this.KiWaypoint.SimulatedDepartLocation;
    set => this.KiWaypoint.SimulatedDepartLocation = value;
  }

  public virtual KiAppLocationEx StoredApproachLocation
  {
    get => this.KiWaypoint.StoredApproachLocation;
    set => this.KiWaypoint.StoredApproachLocation = value;
  }

  public virtual KiAppLocationEx StoredDepartLocation
  {
    get => this.KiWaypoint.StoredDepartLocation;
    set => this.KiWaypoint.StoredDepartLocation = value;
  }

  public virtual object UILockedStatus
  {
    get
    {
      object uiLockedStatus = (object) null;
      if (!this.Locked && !this.KiWaypoint.TemporaryLocked || !this.Active)
        uiLockedStatus = (object) this.KiWaypoint.Fixed;
      return uiLockedStatus;
    }
    set
    {
      this.KiWaypoint.Fixed = (bool) value;
      this.UILockedStatusDidChanged();
    }
  }

  public void UILockedStatusDidChanged() => this.NotifyPropertyChanged("UILockedStatus");

  public virtual bool Fixed
  {
    get => this.KiWaypoint.Fixed;
    set
    {
      this.KiWaypoint.Fixed = value;
      this.UILockedStatusDidChanged();
    }
  }

  public virtual bool Locked
  {
    get => this.KiWaypoint.Locked;
    set
    {
      this.KiWaypoint.Locked = value;
      this.UILockedStatusDidChanged();
    }
  }

  public virtual bool Active => this.KiWaypoint.Active;

  public CApAPPMotionType MotionType
  {
    get => (CApAPPMotionType) this.KiWaypoint.MotionType;
    set
    {
      this.KiWaypoint.MotionType = (KiAppMotionType) value;
      this.MotionTypeDidDidChanged();
    }
  }

  public void MotionTypeDidDidChanged() => this.NotifyPropertyChanged("MotionTypeName");

  public double MotionSpeed
  {
    get => this.KiWaypoint.MotionSpeed;
    set => this.KiWaypoint.MotionSpeed = value;
  }

  public void PropertyDidChanged(CApAPPWaypointProperty i_property)
  {
    switch (i_property)
    {
      case CApAPPWaypointProperty.Fixed:
        this.UILockedStatusDidChanged();
        break;
      case CApAPPWaypointProperty.MotionType:
        this.MotionTypeDidDidChanged();
        break;
      case CApAPPWaypointProperty.Zone:
        this.ZoneNameDidChanged();
        break;
      case CApAPPWaypointProperty.Clash:
        this.StatusDidChanged();
        break;
      case CApAPPWaypointProperty.Status:
        this.WaypointPlanSuccessDidChanged();
        break;
    }
  }

  public static CApAPPMotionType ConvertStringToMotionType(string i_motionType)
  {
    CApAPPMotionType motionType = CApAPPMotionType.JointMotion;
    switch (i_motionType)
    {
      case "Linear":
        motionType = CApAPPMotionType.LinearMotion;
        break;
      case "Joint":
        motionType = CApAPPMotionType.JointMotion;
        break;
    }
    return motionType;
  }

  public bool IsSimular(CApAPPWaypoint wp) => this.KiWaypoint.IsSimilar(wp.KiWaypoint);

  public static string ConvertWpStatusToString(CApAPPWaypointStatus i_wpStatus)
  {
    string str;
    switch (i_wpStatus)
    {
      case CApAPPWaypointStatus.Free:
        str = "Free";
        break;
      case CApAPPWaypointStatus.Clash:
        str = "Clash";
        break;
      case CApAPPWaypointStatus.Tolerance:
        str = "Tolerance";
        break;
      case CApAPPWaypointStatus.SectionVolume:
        str = "SV Clash";
        break;
      default:
        str = "N/A";
        break;
    }
    return str;
  }

  public static CApAPPWaypointStatus ConvertStringToStatus(string i_wpStatusStr)
  {
    CApAPPWaypointStatus status = CApAPPWaypointStatus.Undefined;
    switch (i_wpStatusStr)
    {
      case "Clash":
        status = CApAPPWaypointStatus.Clash;
        break;
      case "Free":
        status = CApAPPWaypointStatus.Free;
        break;
      case "Tolerance":
        status = CApAPPWaypointStatus.Tolerance;
        break;
    }
    return status;
  }

  public event PropertyChangedEventHandler PropertyChanged;

  protected void NotifyPropertyChanged(string info)
  {
    if (this.PropertyChanged == null)
      return;
    this.PropertyChanged((object) this, new PropertyChangedEventArgs(info));
  }
}
